home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / compress / unzip531.zip / unzip.h < prev    next >
C/C++ Source or Header  |  1997-05-31  |  17KB  |  531 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   unzip.h (new)
  4.  
  5.   This header file contains the public macros and typedefs required by
  6.   both the UnZip sources and by any application using the UnZip API.  If
  7.   UNZIP_INTERNAL is defined, it includes unzpriv.h (containing includes,
  8.   prototypes and extern variables used by the actual UnZip sources).
  9.  
  10.   ---------------------------------------------------------------------------*/
  11.  
  12.  
  13. #ifndef __unzip_h   /* prevent multiple inclusions */
  14. #define __unzip_h
  15.  
  16.  
  17. /*---------------------------------------------------------------------------
  18.     Predefined, machine-specific macros.
  19.   ---------------------------------------------------------------------------*/
  20.  
  21. #ifdef POCKET_UNZIP             /* WinCE port */
  22. #  include "wince/punzip.h"     /* must appear before windows.h */
  23. #endif
  24.  
  25. #ifdef WINDLL
  26. #  include <windows.h>
  27. #endif
  28.  
  29. #ifdef __GO32__                 /* MS-DOS extender:  NOT Unix */
  30. #  ifdef unix
  31. #    undef unix
  32. #  endif
  33. #  ifdef __unix
  34. #    undef __unix
  35. #  endif
  36. #  ifdef __unix__
  37. #    undef __unix__
  38. #  endif
  39. #endif
  40.  
  41. #if ((defined(__convex__) || defined(__convexc__)) && !defined(CONVEX))
  42. #  define CONVEX
  43. #endif
  44.  
  45. #if (defined(unix) || defined(__unix) || defined(__unix__))
  46. #  ifndef UNIX
  47. #    define UNIX
  48. #  endif
  49. #endif /* unix || __unix || __unix__ */
  50. #if (defined(M_XENIX) || defined(COHERENT) || defined(__hpux))
  51. #  ifndef UNIX
  52. #    define UNIX
  53. #  endif
  54. #endif /* M_XENIX || COHERENT || __hpux */
  55. #if (defined(CONVEX) || defined(MINIX) || defined(_AIX) || defined(__QNX__))
  56. #  ifndef UNIX
  57. #    define UNIX
  58. #  endif
  59. #endif /* CONVEX || MINIX || _AIX || __QNX__ */
  60.  
  61. #if (defined(VM_CMS) || defined(MVS))
  62. #  define CMS_MVS
  63. #endif
  64.  
  65. #if (defined(__OS2__) && !defined(OS2))
  66. #  define OS2
  67. #endif
  68.  
  69. #if (defined(__VMS) && !defined(VMS))
  70. #  define VMS
  71. #endif
  72.  
  73. #if (defined(__WIN32__) && !defined(WIN32))
  74. #  define WIN32
  75. #endif
  76.  
  77. #ifdef __COMPILER_KCC__
  78. #  include <c-env.h>
  79. #  ifdef SYS_T20
  80. #    define TOPS20
  81. #  endif
  82. #endif /* __COMPILER_KCC__ */
  83.  
  84. /* Borland C does not define __TURBOC__ if compiling for a 32-bit platform */
  85. #ifdef __BORLANDC__
  86. #  ifndef __TURBOC__
  87. #    define __TURBOC__
  88. #  endif
  89. #  if (!defined(__MSDOS__) && !defined(OS2) && !defined(WIN32))
  90. #    define __MSDOS__
  91. #  endif
  92. #endif
  93.  
  94. /* define MSDOS for Turbo C (unless OS/2) and Power C as well as Microsoft C */
  95. #ifdef __POWERC
  96. #  define __TURBOC__
  97. #  define MSDOS
  98. #endif /* __POWERC */
  99.  
  100. #if (defined(__MSDOS__) && !defined(MSDOS))   /* just to make sure */
  101. #  define MSDOS
  102. #endif
  103.  
  104. #if (defined(linux) && !defined(LINUX))
  105. #  define LINUX
  106. #endif
  107.  
  108. #ifdef __riscos
  109. #  define RISCOS
  110. #endif
  111.  
  112. /* use prototypes and ANSI libraries if __STDC__, or Microsoft or Borland C, or
  113.  * Silicon Graphics, or Convex?, or IBM C Set/2, or GNU gcc/emx, or Watcom C,
  114.  * or Macintosh, or Windows NT, or Sequent, or Atari or IBM RS/6000.
  115.  */
  116. #if (defined(__STDC__) || defined(MSDOS) || defined(WIN32) || defined(__EMX__))
  117. #  ifndef PROTO
  118. #    define PROTO
  119. #  endif
  120. #  ifndef MODERN
  121. #    define MODERN
  122. #  endif
  123. #endif
  124. #if (defined(__IBMC__) || defined(__BORLANDC__) || defined(__WATCOMC__))
  125. #  ifndef PROTO
  126. #    define PROTO
  127. #  endif
  128. #  ifndef MODERN
  129. #    define MODERN
  130. #  endif
  131. #endif
  132. #if (defined(THINK_C) || defined(MPW) || defined(ATARI_ST) || defined(RISCOS))
  133. #  ifndef PROTO
  134. #    define PROTO
  135. #  endif
  136. #  ifndef MODERN
  137. #    define MODERN
  138. #  endif
  139. #endif
  140. /* Sequent running Dynix/ptx:  non-modern compiler */
  141. #if (defined(_AIX) || defined(sgi) || (defined(_SEQUENT_) && !defined(PTX)))
  142. #  ifndef PROTO
  143. #    define PROTO
  144. #  endif
  145. #  ifndef MODERN
  146. #    define MODERN
  147. #  endif
  148. #endif
  149. #if (defined(CMS_MVS) || defined(__BEOS__))  /* || defined(CONVEX) */
  150. #  ifndef PROTO
  151. #    define PROTO
  152. #  endif
  153. #  ifndef MODERN
  154. #    define MODERN
  155. #  endif
  156. #endif
  157.  
  158. /* turn off prototypes if requested */
  159. #if (defined(NOPROTO) && defined(PROTO))
  160. #  undef PROTO
  161. #endif
  162.  
  163. /* used to remove arguments in function prototypes for non-ANSI C */
  164. #ifdef PROTO
  165. #  define OF(a) a
  166. #else
  167. #  define OF(a) ()
  168. #endif
  169.  
  170. /* enable the "const" keyword only if MODERN and if not otherwise instructed */
  171. #ifdef MODERN
  172. #  if (!defined(ZCONST) && (defined(USE_CONST) || !defined(NO_CONST)))
  173. #    define ZCONST const
  174. #  endif
  175. #endif
  176.  
  177. #ifndef ZCONST
  178. #  define ZCONST
  179. #endif
  180.  
  181. /* bad or (occasionally?) missing stddef.h: */
  182. #if (defined(M_XENIX) || defined(DNIX))
  183. #  define NO_STDDEF_H
  184. #endif
  185.  
  186. #if (defined(M_XENIX) && !defined(M_UNIX))   /* SCO Xenix only, not SCO Unix */
  187. #  define SCO_XENIX
  188. #  define NO_LIMITS_H        /* no limits.h, but MODERN defined */
  189. #  define NO_UID_GID         /* no uid_t/gid_t */
  190. #  define size_t int
  191. #endif
  192.  
  193. #ifdef realix   /* Modcomp Real/IX, real-time SysV.3 variant */
  194. #  define SYSV
  195. #  define NO_UID_GID         /* no uid_t/gid_t */
  196. #endif
  197.  
  198. #if (defined(_AIX) && !defined(_ALL_SOURCE))
  199. #  define _ALL_SOURCE
  200. #endif
  201.  
  202. #if defined(apollo)          /* defines __STDC__ */
  203. #    define NO_STDLIB_H
  204. #endif
  205.  
  206. #ifdef DNIX
  207. #  define SYSV
  208. #  define SHORT_NAMES         /* 14-char limitation on path components */
  209. /* #  define FILENAME_MAX  14 */
  210. #  define FILENAME_MAX  NAME_MAX    /* GRR:  experiment */
  211. #endif
  212.  
  213. #if (defined(SYSTEM_FIVE) || defined(__SYSTEM_FIVE))
  214. #  ifndef SYSV
  215. #    define SYSV
  216. #  endif
  217. #endif /* SYSTEM_FIVE || __SYSTEM_FIVE */
  218. #if (defined(M_SYSV) || defined(M_SYS5))
  219. #  ifndef SYSV
  220. #    define SYSV
  221. #  endif
  222. #endif /* M_SYSV || M_SYS5 */
  223. /* __SVR4 and __svr4__ catch Solaris on at least some combos of compiler+OS */
  224. #if (defined(__SVR4) || defined(__svr4__) || defined(sgi) || defined(__hpux))
  225. #  ifndef SYSV
  226. #    define SYSV
  227. #  endif
  228. #endif /* __SVR4 || __svr4__ || sgi || __hpux */
  229. #if (defined(LINUX) || defined(__QNX__))
  230. #  ifndef SYSV
  231. #    define SYSV
  232. #  endif
  233. #endif /* LINUX || __QNX__ */
  234.  
  235. #if (defined(ultrix) || defined(__ultrix) || defined(bsd4_2))
  236. #  if (!defined(BSD) && !defined(SYSV))
  237. #    define BSD
  238. #  endif
  239. #endif /* ultrix || __ultrix || bsd4_2 */
  240. #if (defined(sun) || defined(pyr) || defined(CONVEX))
  241. #  if (!defined(BSD) && !defined(SYSV))
  242. #    define BSD
  243. #  endif
  244. #endif /* sun || pyr || CONVEX */
  245.  
  246. #ifdef pyr  /* Pyramid:  has BSD and AT&T "universes" */
  247. #  ifdef BSD
  248. #    define pyr_bsd
  249. #    define USE_STRINGS_H  /* instead of more common string.h */
  250. #    define ZMEM           /* ZMEM now uses bcopy/bzero: not in AT&T universe */
  251. #  endif                   /* (AT&T memcpy claimed to be very slow, though) */
  252. #  define DECLARE_ERRNO
  253. #endif /* pyr */
  254.  
  255. /* stat() bug for Borland, VAX C (also GNU?), and Atari ST MiNT on TOS
  256.  * filesystems:  returns 0 for wildcards!  (returns 0xffffffff on Minix
  257.  * filesystem or `U:' drive under Atari MiNT.)  Watcom C was previously
  258.  * included on this list; it would be good to know what version the problem
  259.  * was fixed at, if it did exist.  Watcom 10.6 has a separate stat() problem:
  260.  * it fails on "." when the current directory is a root.  This is covered by
  261.  * giving it a separate definition of SSTAT in OS-specific header files. */
  262. #if (defined(__TURBOC__) || defined(VMS) || defined(__MINT__))
  263. #  define WILD_STAT_BUG
  264. #endif
  265.  
  266. #ifdef WILD_STAT_BUG
  267. #  define SSTAT(path,pbuf) (iswild(path) || stat(path,pbuf))
  268. #else
  269. #  define SSTAT stat
  270. #endif
  271.  
  272. #ifdef REGULUS  /* returns the inode number on success(!)...argh argh argh */
  273. #  define stat(p,s) zstat(p,s)
  274. #endif
  275.  
  276. #define STRNICMP zstrnicmp
  277.  
  278.  
  279. /*---------------------------------------------------------------------------
  280.     OS-dependent includes
  281.   ---------------------------------------------------------------------------*/
  282.  
  283. #ifdef EFT
  284. #  define LONGINT off_t  /* Amdahl UTS nonsense ("extended file types") */
  285. #else
  286. #  define LONGINT long
  287. #endif
  288.  
  289. #ifdef MODERN
  290. #  ifndef NO_STDDEF_H
  291. #    include <stddef.h>
  292. #  endif
  293. #  ifndef NO_STDLIB_H
  294. #    include <stdlib.h>  /* standard library prototypes, malloc(), etc. */
  295. #  endif
  296.    typedef size_t extent;
  297.    typedef void zvoid;
  298. #else /* !MODERN */
  299. #  ifndef AOS_VS         /* mostly modern? */
  300. #    ifndef CMS_MVS
  301.        LONGINT lseek();
  302. #    endif
  303. #    ifdef VAXC          /* not fully modern, but does have stdlib.h and void */
  304. #      include <stdlib.h>
  305. #    else
  306.        char *malloc();
  307. #      define void int
  308. #    endif /* ?VAXC */
  309. #  endif /* !AOS_VS */
  310.    typedef unsigned int extent;
  311.    typedef char zvoid;
  312. #endif /* ?MODERN */
  313.  
  314.  
  315. /*---------------------------------------------------------------------------
  316.     Grab system-dependent definition of EXPENTRY for prototypes below.
  317.   ---------------------------------------------------------------------------*/
  318.  
  319. #if 0
  320. #if (defined(OS2) && !defined(FUNZIP))
  321. #  ifdef UNZIP_INTERNAL
  322. #    define INCL_NOPM
  323. #    define INCL_DOSNLS
  324. #    define INCL_DOSPROCESS
  325. #    define INCL_DOSDEVICES
  326. #    define INCL_DOSDEVIOCTL
  327. #    define INCL_DOSERRORS
  328. #    define INCL_DOSMISC
  329. #    ifdef OS2DLL
  330. #      define INCL_REXXSAA
  331. #      include <rexxsaa.h>
  332. #    endif
  333. #  endif /* UNZIP_INTERNAL */
  334. #  include <os2.h>
  335. #  define UZ_EXP EXPENTRY
  336. #endif /* OS2 && !FUNZIP */
  337. #endif /* 0 */
  338.  
  339. #if (defined(OS2) && !defined(FUNZIP))
  340. #  if defined(__IBMC__) || defined(__WATCOMC__)
  341. #    define UZ_EXP  _System    /* compiler keyword */
  342. #  else
  343. #    define UZ_EXP
  344. #  endif
  345. #endif /* OS2 && !FUNZIP */
  346.  
  347. #ifdef WINDLL
  348. #  ifndef EXPENTRY
  349. #    define UZ_EXP WINAPI
  350. #  else
  351. #    define UZ_EXP EXPENTRY
  352. #  endif
  353. #endif
  354.  
  355. #ifndef UZ_EXP
  356. #  define UZ_EXP
  357. #endif
  358.  
  359.  
  360. /*---------------------------------------------------------------------------
  361.     Public typedefs.
  362.   ---------------------------------------------------------------------------*/
  363.  
  364. typedef unsigned char   uch;    /* code assumes unsigned bytes; these type-  */
  365. typedef unsigned short  ush;    /*  defs replace byte/UWORD/ULONG (which are */
  366. typedef unsigned long   ulg;    /*  predefined on some systems) & match zip  */
  367.  
  368. /* InputFn is not yet used and is likely to change: */
  369. #ifdef PROTO
  370.    typedef int   (UZ_EXP MsgFn)     (zvoid *pG, uch *buf, ulg size, int flag);
  371.    typedef int   (UZ_EXP InputFn)   (zvoid *pG, uch *buf, int *size, int flag);
  372.    typedef void  (UZ_EXP PauseFn)   (zvoid *pG, ZCONST char *prompt, int flag);
  373.    typedef int   (UZ_EXP PasswdFn)  (zvoid *pG, int *rcnt, char *pwbuf,
  374.                                      int size, ZCONST char *zfn,
  375.                                      ZCONST char *efn);
  376. #ifdef WINDLL
  377.    typedef int   (WINAPI ReplaceFn) (char *);
  378.    typedef void  (WINAPI SoundFn)   (void);
  379. #endif
  380. #else /* !PROTO */
  381.    typedef int   (UZ_EXP MsgFn)     ();
  382.    typedef int   (UZ_EXP InputFn)   ();
  383.    typedef void  (UZ_EXP PauseFn)   ();
  384.    typedef int   (UZ_EXP PasswdFn)  ();
  385. #ifdef WINDLL
  386.    typedef int   (WINAPI ReplaceFn) ();
  387.    typedef void  (WINAPI SoundFn)   ();
  388. #endif
  389. #endif /* ?PROTO */
  390.  
  391. typedef struct _UzpBuffer {    /* rxstr */
  392.     ulg   strlength;           /* length of string */
  393.     char  *strptr;             /* pointer to string */
  394. } UzpBuffer;
  395.  
  396. typedef struct _UzpInit {
  397.     ulg structlen;             /* length of the struct being passed */
  398.  
  399.     /* GRR: can we assume that each of these is a 32-bit pointer?  if not,
  400.      * does it matter? add "far" keyword to make sure? */
  401.     MsgFn *msgfn;
  402.     InputFn *inputfn;
  403.     PauseFn *pausefn;
  404.  
  405.     void (* UZ_EXP userfn)();  /* user init function to be called after */
  406.                                /*  globals constructed and initialized */
  407.  
  408.     /* pointer to program's environment area or something? */
  409.     /* hooks for performance testing? */
  410.     /* hooks for extra unzip -v output? (detect CPU or other hardware?) */
  411.     /* anything else?  let me (Greg) know... */
  412. } UzpInit;
  413.  
  414. /* intended to be a private struct: */
  415. typedef struct _ver {
  416.     uch major;              /* e.g., integer 5 */
  417.     uch minor;              /* e.g., 2 */
  418.     uch patchlevel;         /* e.g., 0 */
  419.     uch not_used;
  420. } _version_type;
  421.  
  422. typedef struct _UzpVer {
  423.     ulg structlen;          /* length of the struct being passed */
  424.     ulg flag;               /* bit 0: is_beta   bit 1: uses_zlib */
  425.     char *betalevel;        /* e.g., "g BETA" or "" */
  426.     char *date;             /* e.g., "4 Sep 95" (beta) or "4 September 1995" */
  427.     char *zlib_version;     /* e.g., "0.95" or NULL */
  428.     _version_type unzip;
  429.     _version_type zipinfo;
  430.     _version_type os2dll;
  431.     _version_type windll;
  432. } UzpVer;
  433.  
  434. typedef struct central_directory_file_header { /* CENTRAL */
  435.     uch version_made_by[2];
  436.     uch version_needed_to_extract[2];
  437.     ush general_purpose_bit_flag;
  438.     ush compression_method;
  439.     ush last_mod_file_time;
  440.     ush last_mod_file_date;
  441.     ulg crc32;
  442.     ulg csize;
  443.     ulg ucsize;
  444.     ush filename_length;
  445.     ush extra_field_length;
  446.     ush file_comment_length;
  447.     ush disk_number_start;
  448.     ush internal_file_attributes;
  449.     ulg external_file_attributes;
  450.     ulg relative_offset_local_header;
  451. } cdir_file_hdr;
  452.  
  453.  
  454. #define UZPINIT_LEN   sizeof(UzpInit)
  455. #define UZPVER_LEN    sizeof(UzpVer)
  456. #define cbList(func)  int (* UZ_EXP func)(char *filename, cdir_file_hdr *crec)
  457.  
  458.  
  459. /*---------------------------------------------------------------------------
  460.     Return (and exit) values of the public UnZip API functions.
  461.   ---------------------------------------------------------------------------*/
  462.  
  463. /* external return codes */
  464. #define PK_OK              0   /* no error */
  465. #define PK_COOL            0   /* no error */
  466. #define PK_GNARLY          0   /* no error */
  467. #define PK_WARN            1   /* warning error */
  468. #define PK_ERR             2   /* error in zipfile */
  469. #define PK_BADERR          3   /* severe error in zipfile */
  470. #define PK_MEM             4   /* insufficient memory (during initialization) */
  471. #define PK_MEM2            5   /* insufficient memory (password failure) */
  472. #define PK_MEM3            6   /* insufficient memory (file decompression) */
  473. #define PK_MEM4            7   /* insufficient memory (memory decompression) */
  474. #define PK_MEM5            8   /* insufficient memory (not yet used) */
  475. #define PK_NOZIP           9   /* zipfile not found */
  476. #define PK_PARAM          10   /* bad or illegal parameters specified */
  477. #define PK_FIND           11   /* no files found */
  478. #define PK_DISK           50   /* disk full */
  479. #define PK_EOF            51   /* unexpected EOF */
  480.  
  481. #define IZ_CTRLC          80   /* user hit ^C to terminate */
  482. #define IZ_UNSUP          81   /* no files found: all unsup. compr/encrypt. */
  483. #define IZ_BADPWD         82   /* no files found: all had bad password */
  484.  
  485. /* internal and DLL-only return codes */
  486. #define IZ_DIR            76   /* potential zipfile is a directory */
  487. #define IZ_CREATED_DIR    77   /* directory created: set time and permissions */
  488. #define IZ_VOL_LABEL      78   /* volume label, but can't set on hard disk */
  489. #define IZ_EF_TRUNC       79   /* local extra field truncated (PKZIP'd) */
  490.  
  491. /* return codes of password fetches (negative = user abort; positive = error) */
  492. #define IZ_PW_ENTERED      0   /* got some password string; use/try it */
  493. #define IZ_PW_CANCEL      -1   /* no password available (for this entry) */
  494. #define IZ_PW_CANCELALL   -2   /* no password, skip any further pwd. request */
  495. #define IZ_PW_ERROR        5   /* = PK_MEM2 : failure (no mem, no tty, ...) */
  496.  
  497.  
  498. /*---------------------------------------------------------------------------
  499.     Prototypes for public UnZip API (DLL) functions.
  500.   ---------------------------------------------------------------------------*/
  501.  
  502. int      UZ_EXP UzpMain            OF((int argc, char **argv));
  503. int      UZ_EXP UzpAltMain         OF((int argc, char **argv, UzpInit *init));
  504. UzpVer * UZ_EXP UzpVersion         OF((void));
  505. int      UZ_EXP UzpUnzipToMemory   OF((char *zip, char *file,
  506.                                        UzpBuffer *retstr));
  507. int      UZ_EXP UzpFileTree        OF((char *name, cbList(callBack),
  508.                                        char *cpInclude[], char *cpExclude[]));
  509.  
  510. /* default I/O functions (can be swapped out via UzpAltMain() entry point): */
  511.  
  512. int      UZ_EXP UzpMessagePrnt   OF((zvoid *pG, uch *buf, ulg size, int flag));
  513. int      UZ_EXP UzpMessageNull   OF((zvoid *pG, uch *buf, ulg size, int flag));
  514. int      UZ_EXP UzpInput         OF((zvoid *pG, uch *buf, int *size, int flag));
  515. void     UZ_EXP UzpMorePause     OF((zvoid *pG, ZCONST char *prompt, int flag));
  516. int      UZ_EXP UzpPassword      OF((zvoid *pG, int *rcnt, char *pwbuf,
  517.                                      int size, ZCONST char *zfn,
  518.                                      ZCONST char *efn));
  519.  
  520.  
  521. /*---------------------------------------------------------------------------
  522.     Remaining private stuff for UnZip compilation.
  523.   ---------------------------------------------------------------------------*/
  524.  
  525. #ifdef UNZIP_INTERNAL
  526. #  include "unzpriv.h"
  527. #endif
  528.  
  529.  
  530. #endif /* !__unzip_h */
  531.